package cn.stack.springframework.test.bean;

import cn.bugstack.springframework.beans.BeansException;
import cn.bugstack.springframework.beans.factory.BeanFactory;
import cn.bugstack.springframework.beans.factory.DisposableBean;
import cn.bugstack.springframework.beans.factory.InitializingBean;
import cn.bugstack.springframework.context.ApplicationContext;

public class UserService implements InitializingBean, DisposableBean {

    private ApplicationContext applicationContext;
    private BeanFactory beanFactory;

    private String uId;
    private String company;
    private String location;
    private UserDao userDao;

    public UserService() {
    }

    public UserService(String uId, String company, String location, UserDao userDao) {
        this.uId = uId;
        this.company = company;
        this.location = location;
        this.userDao = userDao;
    }

    public String queryUserInfo(){
        return userDao.queryName(uId)+"公司:"+company+",地点:"+location;
    }


    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public void setBeanFactory(BeanFactory beanFactory) {
        this.beanFactory = beanFactory;
    }

    public BeanFactory getBeanFactory() {
        return beanFactory;
    }

    /**
     * 获取
     * @return uId
     */
    public String getUId() {
        return uId;
    }

    /**
     * 设置
     * @param uId
     */
    public void setUId(String uId) {
        this.uId = uId;
    }

    /**
     * 获取
     * @return company
     */
    public String getCompany() {
        return company;
    }

    /**
     * 设置
     * @param company
     */
    public void setCompany(String company) {
        this.company = company;
    }

    /**
     * 获取
     * @return location
     */
    public String getLocation() {
        return location;
    }

    /**
     * 设置
     * @param location
     */
    public void setLocation(String location) {
        this.location = location;
    }

    /**
     * 获取
     * @return userDao
     */
    public UserDao getUserDao() {
        return userDao;
    }

    /**
     * 设置
     * @param userDao
     */
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public String toString() {
        return "UserService{uId = " + uId + ", company = " + company + ", location = " + location + ", userDao = " + userDao + "}";
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("执行: UserService.destroy");
    }


    @Override
    public void afterPropertiesSet() throws BeansException {
        System.out.println("执行:UserService.afterPropertiesSet");
    }
}
